<?php

declare(strict_types=1);

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 * 主播白名单
 */
class WhiteHost extends Model
{
    protected $table = 'white_host';

    protected $fillable = [
        'user_id', 'flag'
    ];

    static function getHosts()
    {
        $list = self::where(['flag' => 1])->pluck('user_id')->toArray();
        return array_unique($list);
    }

    static function checkWhite($userId = 0)
    {
        return self::where(['user_id' => $userId, 'flag' => 1])->count() > 0;
    }

    static function addHost($userId = 0)
    {
        return self::create([
            'user_id' => $userId,
            'flag' => 1
        ]);
    }
}
